package com.heima.article.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.article.mapper.ApArticleConfigMapper;
import com.heima.article.service.ApArticleConfigService;
import com.heima.common.constants.wemedia.WemediaConstants;
import com.heima.common.exception.CustException;
import com.heima.model.article.pojos.ApArticleConfig;
import com.heima.model.common.enums.AppHttpCodeEnum;
import org.springframework.stereotype.Service;

@Service
public class ApArticleConfigServiceImpl extends ServiceImpl<ApArticleConfigMapper, ApArticleConfig> implements ApArticleConfigService {

    @Override
    public void NewsForUpArticle(Long articleId) {
        if (articleId == null){
            CustException.cust(AppHttpCodeEnum.PARAM_INVALID,"获取到的文章ID不能为空");
        }
        ApArticleConfig articleConfig = getOne(Wrappers.<ApArticleConfig>lambdaQuery().eq(ApArticleConfig::getArticleId, articleId));
        if (articleConfig == null){
            CustException.cust(AppHttpCodeEnum.DATA_NOT_EXIST,"文章配置信息不存在");
        }
        update(Wrappers.<ApArticleConfig>lambdaUpdate().set(ApArticleConfig::getIsDown, false).eq(ApArticleConfig::getArticleId, articleId));
    }

    @Override
    public void NewsForDownArticle(Long articleId) {
        if (articleId == null){
            CustException.cust(AppHttpCodeEnum.PARAM_INVALID,"获取到的文章ID不能为空");
        }
        ApArticleConfig articleConfig = getOne(Wrappers.<ApArticleConfig>lambdaQuery().eq(ApArticleConfig::getArticleId, articleId));
        if (articleConfig == null){
            CustException.cust(AppHttpCodeEnum.DATA_NOT_EXIST,"文章配置信息不存在");
        }
        update(Wrappers.<ApArticleConfig>lambdaUpdate().set(ApArticleConfig::getIsDown, true).eq(ApArticleConfig::getArticleId, articleId));
    }
}